﻿using SWF = System.Windows.Forms;
using DevExpress.XtraEditors;
using System.Data;

namespace Mota.XMLControls
{
    /// <summary>
    /// Class represent CheckBox visual control based on DX CheckEdit control
    /// </summary>
    public class DXGuiCheckBox:GuiCheckBox
    {
        public DXGuiCheckBox()
        {
            visualControl = new CheckEdit();
            (visualControl as CheckEdit).EditValueChanged += DXGuiCheckBox_EditValueChanged;
        }

        void DXGuiCheckBox_EditValueChanged(object sender, System.EventArgs e)
        {
            this.ChangeEventCall(null);
        }
        /// <summary>
        /// Text property of DX CheckEdit
        /// </summary>
        public override string Text
        {
            get
            {
                return (visualControl as CheckEdit).Text;
            }
            set
            {
                (visualControl as CheckEdit).Text = value;
            }
        }
        /// <summary>
        /// Set DataBinding for DX CheckEdit control on property Checked
        /// </summary>
        /// <param name="valueBinding">main binding with current record value</param>
        public override void SetValue(object valueBinding)
        {
            (visualControl as SWF.Control).DataBindings.Add("Checked", valueBinding as SWF.BindingSource, XmlAttributes["XMLAttribute"], true);

        }
        /// <summary>
        /// Dummy for this class.
        /// getter allways return null
        /// </summary>
        public override object Binding
        {
            get
            {
                //
                return null;
            }
            set
            {
                //
            }
        }

        public override object GetValue()
        {
            return (visualControl as CheckEdit).Checked;
        }
    }
}
